import uniqueId from "@form-create/utils/lib/unique";
import { localeProps, makeRequiredRule } from "../../utils";

const label = "输入框";
const name = "a-input";

export default {
  icon: "icon-input",
  label,
  name,
  rule({ t }) {
    return {
      type: name,
      field: uniqueId(),
      title: t("components.input.name"),
      info: "",
      $required: false,
      props: {},
    };
  },
  props(_, { t }) {
    return localeProps(t, name + ".props", [
      makeRequiredRule(),
      {
        type: "input",
        field: "placeholder",
        title: "输入框提示文字",
      },
      {
        type: "select",
        field: "type",
        title: "输入框类型",
        value: "text",
        options: [
          {
            label: "文本",
            value: "text",
          },
          {
            label: "数字",
            value: "number",
          },
          {
            label: "密码",
            value: "password",
          },
        ],
      },
      {
        type: "inputNumber",
        field: "maxlength",
        title: "最大输入长度",
        props: {
          min: 0,
        },
      },
      {
        type: "switch",
        field: "allowClear",
        title: "是否可清空",
      },
      {
        type: "switch",
        field: "disabled",
        title: "是否禁用",
      },
      {
        type: "switch",
        field: "readonly",
        title: "是否只读",
      },
    ]);
  },
};
